package com.epro.dx.util;

import android.app.AlertDialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.epro.dx.R;
import com.epro.dx.listenner.PaymentMethodDialogOnClickListenner;

public class PaymentMethodDialogUtils {

	private PaymentMethodDialogOnClickListenner pmdClickListenner;

	public PaymentMethodDialogUtils(
			PaymentMethodDialogOnClickListenner pmdClickListenner) {
           this.pmdClickListenner=pmdClickListenner;
	}

	/**
	 * 显示选择支付方式弹窗
	 * */
	public void showChoosePaymentWindow(Context context) {
		// Builder builder = new AlertDialog.Builder(this);
		 View dialogView = LinearLayout.inflate(context, R.layout.dialog_choose_payment,
		 null);
		final AlertDialog dialog = new AlertDialog.Builder(context).create();
		dialog.show();
		// 关键在下面的两行,使用window.setContentView,替换整个对话框窗口的布局
		Window window = dialog.getWindow();
		window.setGravity(Gravity.CENTER);
		window.setContentView(dialogView);
		RelativeLayout paypal = (RelativeLayout) dialogView
				.findViewById(R.id.payment_method_paypal);
		RelativeLayout creditcard = (RelativeLayout) dialogView
				.findViewById(R.id.payment_method_creditcard);
		paypal.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO 执行PayPal支付逻辑
				if (null != pmdClickListenner) {
					pmdClickListenner.onPayPalClick();
				}
				dialog.dismiss();
			}
		});
		creditcard.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO 执行信用卡支付逻辑
				if (null != pmdClickListenner) {
					pmdClickListenner.onCreditCardClick();
				}
				dialog.dismiss();
			}
		});
	}
}
